package MemTrac::Templates;
use strict;
use lib '..';
use MemTrac::Utils;

require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw( BASIC_HEAD_TEMPLATE BASIC_FOOT_TEMPLATE ERROR_TEMPLATE MEMBERLIST_TABLE ALT_FORM CONFIG_FORM );
our @EXPORT_OK = qw();

use constant BASIC_HEAD_TEMPLATE => compile_template(q{
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title>Di-Tron - Member Tracker</title>
        <style type="text/css">
            .rightb{border-right: 5px solid grey;} .num{text-align:right;} .cen{text-align:center;} .red{color:red;font-weight:bold;}
            .cache{color: #96969B;} td{padding:0px 3px; white-space:nowrap; text-align:left;border:1px solid white;} td.left{text-align:left;}
            th{padding:0px 3px; white-space:nowrap; text-align:center;} .ec{border-collapse:collapse;border:1px solid gray;}
            .ec th{border:1px solid gray;} .ec th.rightb{border-right:5px solid gray;} .ec td{border:1px solid gray;} .ec
            td.rightb{border-right:5px solid gray;} table {border-collapse: collapse;} .alts{margin-left:1em;} .director{color:yellow;}
            .error{border: 2px solid red;font-weight:bold;padding:.5em;}
        </style>
    </head>
    <body bgcolor="#2D2D37" text="#ffffff" link="#ff8a00" vlink="#ff8a00">
    <h5><a href="<var $self>">Memberlist</a> (<a href="<var $self>?norefresh=1">Cached</a>)</h5>
   <br><hr>
});

use constant BASIC_FOOT_TEMPLATE => compile_template(q{
        <br><br><hr>
    </body>
</html>
});

use constant ERROR_TEMPLATE => compile_template(q{
        <center>
        <br><br><br><br>
          <h1><var $error></h1><br><br>
        </center>
});

use constant MEMBERLIST_TABLE => compile_template(q{
    <span style="float:right;">Next refresh in <var $next_refresh>.</span>
<table>
    <tr><th>Name</th><th>Last Seen</th><th>For</th><th>Functions</th></tr>
    
    <loop $member_list><tr>
        <td<if $type==1> class="director"</if>><var $name></td>
        <td class="num"><var last_seen($logonDateTime,$logoffDateTime)> ago</td>
        <td class="num"><var seen_for($logonDateTime,$logoffDateTime)></td>
        <td><a href="<var $self>?task=toggle_dir&amp;id=<var $characterID>">Director</a> <a href="<var $self>?task=show_alt_choice&amp;id=<var $characterID>">Alt</a></td>
    </tr>
    <if $alts><tr>
        <td colspan=4>
            <table class="alts">
                <loop $alts><tr>
                    <td<if $type==1> class="director"</if>><var $name></td>
                    <td class="num"><var last_seen($logonDateTime,$logoffDateTime)> ago</td>
                    <td class="num"><var make_duration($logonDateTime,$logoffDateTime)></td>
                    <td><a href="<var $self>?task=toggle_dir&amp;id=<var $characterID>">Director</a> <a href="<var $self>?task=show_alt_choice&amp;id=<var $characterID>">Alt</a></td>
                </tr></loop>
            </table>
        </td>
    </tr></if></loop>

</table>
});

use constant ALT_FORM => compile_template(q{
Who is the main of <var $alt_name>? 
<form action="<var $self>" method="post">
<input type="hidden" name="task" value="make_alt" />
<input type="hidden" name="alt_id" value="<var $alt_id>" />

<select name="main">
<option value="-1">Noone</option>
<option value="0">Unknown</option>
<loop $chars>
<option value="<var $characterID>"><var $name></option>
</loop>
</select>

<input type="submit" value="Go" />
</form>
});

use constant CONFIG_FORM => compile_template(q{
<if $msg><div class="error"><var $msg></div><br></if>
<form action="<var $self>" method="post">
<input type="hidden" name="task" value="write_initial_conf" />

Language: <select name="lang">
<loop $langs>
<option value="<var $index>"<if $lang eq $index> selected</if>><var $name></option>
</loop>
</select><br>
<br>
Database Host: <input type="text" name="host" value="<var $host>" /><br>
Database User: <input type="text" name="user" value="<var $user>" /><br>
Database Password: <input type="text" name="password" value="<var $password>" /><br>
Database Name: <input type="text" name="db" value="<var $db>" /><br>
Table Prefix: <input type="text" name="prefix" value="<var $prefix>" /> *optional<br>
<br>
<a href="http://myeve.eve-online.com/api/">Get your API keys from here.</a><br>
User ID: <input type="text" name="userid" value="<var $userid>" /><br>
API Key: <input type="text" name="apikey" value="<var $apikey>" /><br>
Character ID: <input type="text" name="characterID" value="<var $characterID>" /><br>
<br>
<input type="submit" value="Save" />
</form>
});

1;
